import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import {EventPattern} from "@nestjs/microservices"
import * as winston from 'winston';
import { format, transports } from 'winston';

const logger = winston.createLogger({
  level: 'info',
  format: format.combine(
    format.timestamp(),
    format.printf(({ timestamp, level, message }) => `${timestamp} ${level}: ${message}`)
  ),
  transports: [
    new transports.File({ filename: 'combined.log', level: 'info' }),
    new transports.File({ filename: 'error.log', level: 'error' }),
    new transports.Console(), // 保留控制台输出，方便调试
  ],
});

// 2.处理日志事件EventPattern
@Controller()
export class AppController {
  constructor() {}

@EventPattern('log')
 log(text:string):void{
  logger.info(text); // 使用 Winston 记录日志
  console.log(text);
  
 }
}
